home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / Assembler / subroutines / allocmem.asm next >
Encoding:
Assembly Source File  |  1992-08-27  |  2.1 KB  |  67 lines

  1. ;
  2. ; Copyright (c) 1988 Commodore-Amiga, Inc.
  3. ;
  4. ; Executables based on this information may be used in software
  5. ; for Commodore Amiga computers.  All other rights reserved.
  6. ;
  7. ; This information is provided "as is"; no warranties are made.
  8. ; All use is at your own risk, and no liability or responsibility is assumed.
  9. ;
  10.  
  11.         XREF    _LVOAllocMem,_LVOFreeMem
  12.  
  13. ;==============================================================================
  14. ; Success = AllocMemory( memtable )
  15. ;   d0                a0
  16. ;
  17. ; Allocates all memory in the given table and returns false if it failed.
  18. ; memory table is formatted as follows:-
  19. ;
  20. ; size.l,type.w,offset.w
  21. ; ......
  22. ; -1
  23. ;
  24. ; Size is the required size for this chunk of memory.
  25. ; Type is the memory type required, it is always ored with MEMF_CLEAR
  26. ; Offset is the offset to store at (off the a5 global pointer)
  27. ;==============================================================================
  28. AllocMemory    movem.l    a2/a6,-(sp)
  29.         movea.l    SysLib(a5),a6        using exec library
  30.         movea.l    a0,a2            stash memtable address
  31.  
  32. 10$        move.l    (a2)+,d0        get size
  33.         bmi.s    MemAlloced        last entry, return true
  34.         moveq.l    #0,d1
  35.         move.w    (a2)+,d1        get type
  36.         bset.l    #MEMB_CLEAR,d1        clear it too
  37.         jsr    _LVOAllocMem(a6)    allocate it
  38.         move.w    (a2)+,d1        get store offset
  39.         move.l    d0,0(a5,d1.w)        save it
  40.         bne.s    10$            OK, memory fetched
  41. MemAlloced    movem.l    (sp)+,a2/a6        could return 0 if it failed
  42.         rts
  43.  
  44. ;==============================================================================
  45. ; FreeMemory( memtable )
  46. ;         a0
  47. ;
  48. ; Frees all the memory that was allocated by AllocMemory up to the first zero
  49. ; pointer (or allocation that failed).  Use same table as used for AllocMemory.
  50. ;==============================================================================
  51. FreeMemory    movem.l    a2/a6,-(sp)
  52.         movea.l    SysLib(a5),a6        using exec library
  53.         movea.l    a0,a2            stash table pointer
  54.  
  55. 10$        move.l    (a2)+,d0        end of list
  56.         bmi.s    MemFreed        yep, exit now
  57.         move.l    (a2)+,d1        offset to lower word
  58.         move.l    0(a5,d1.w),d1        get pointer
  59.         beq.s    MemFreed        quit! alloc failed on this one
  60.         movea.l    d1,a1
  61.         jsr    _LVOFreeMem(a6)
  62.         bra.s    10$
  63. MemFreed    movem.l    (sp)+,a2/a6
  64.         rts
  65.  
  66.         END
  67.